package org.yly.game.rpggame.domain.model.task;

import java.util.List;
import java.util.Map;

import org.yly.game.rpggame.domain.model.Entity;
import org.yly.game.rpggame.domain.model.Position;
import org.yly.game.rpggame.domain.model.goods.Goods;
import org.yly.game.rpggame.domain.model.player.Player;

/**
 * 游戏任务
 * 
 * @author makefu
 * 
 */
public class Task extends Entity {

	/* 任务基本信息 */
	private String title; // 任务标题
	private String description; // 详细描述
	private Position position; // 任务位置
	private List<RewardItem> rewardItemList; // 任务奖励
	private String publisherId; // 发布人Id

	/* 任务开放条件 */
	private int playerLevel; // 玩家等级
	private String roleId; // 所属角色Id
	private String preCompleteTaskId; // 上一个完成的任务

	/* 任务完成条件 */
	private Map<String, Integer> needKillMonsterIdMap; // 需要杀的怪物ID
	private Map<String, Integer> needGoodsMap; // 需要物品

	private TaskType taskType;

	public Task(String id, String title, String description, Position position, List<RewardItem> rewardItemList,
			String publisherId, String roleId, int playerLevel) {
		super(id);
		this.title = title;
		this.description = description;
		this.position = position;
		this.rewardItemList = rewardItemList;
		this.publisherId = publisherId;
		this.roleId = roleId;
	}

	public String getRoleId() {
		return roleId;
	}

	public TaskType getTaskType() {
		return taskType;
	}

	public List<RewardItem> getRewardItemList() {
		return rewardItemList;
	}

	public String getTitle() {
		return title;
	}

	public String getDescription() {
		return description;
	}

	public Position getPosition() {
		return position;
	}

	public String getPublisherId() {
		return publisherId;
	}

	public Map<String, Integer> getNeedKillMonsterIdMap() {
		return needKillMonsterIdMap;
	}

	public Map<String, Integer> getNeedGoodsMap() {
		return needGoodsMap;
	}

	/**
	 * 验证任务是否开放
	 * 
	 * @return
	 */
	public boolean isOpen(Player player) {
		return this.roleId == player.getRole().id() && this.playerLevel < player.getLevel()
				&& player.completeTask(this.preCompleteTaskId);
	}

	/**
	 * 奖励物品项
	 * 
	 * @author makefu
	 * 
	 */
	public class RewardItem {
		Goods reward;
		int count;
		float rate;
	}

}
